#!/bin/bash
#
# Copyright (C) 2009 Red Hat, Inc.
# Copyright (c) 2000-2003,2006 Silicon Graphics, Inc.  All Rights Reserved.
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it would be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
#
# setup and check for config parameters
#

# all tests should use a common language setting to prevent golden
# output mismatches.
export LANG=C

PATH=".:$PATH"

HOST=`hostname -s`
HOSTOS=`uname -s`

export CHECK_OPTIONS=${CHECK_OPTIONS:="-g auto"}
export PWD=`pwd`

# $1 = prog to look for, $2* = default pathnames if not found in $PATH
set_prog_path()
{
    p=`which $1 2> /dev/null`
    if [ -n "$p" -a -x "$p" ]; then
        echo $p
        return 0
    fi
    p=$1

    shift
    for f; do
        if [ -x $f ]; then
            echo $f
            return 0
        fi
    done

    echo ""
    return 1
}

_fatal()
{
    echo "$*"
    status=1
    exit 1
}

export PERL_PROG="`set_prog_path perl`"
[ "$PERL_PROG" = "" ] && _fatal "perl not found"

export AWK_PROG="`set_prog_path awk`"
[ "$AWK_PROG" = "" ] && _fatal "awk not found"

export SED_PROG="`set_prog_path sed`"
[ "$SED_PROG" = "" ] && _fatal "sed not found"

export BC_PROG="`set_prog_path bc`"
[ "$BC_PROG" = "" ] && _fatal "bc not found"

export DRIVER=${DRIVER:-local}
export WD=${WD:-/tmp/sheepdog}
export STORE=$WD
export SHEEP_PROG=${SHEEP_PROG:-../../sheep/sheep}
export SHEEP=${SHEEP:-$SHEEP_PROG}
export SHEEP_OPTIONS=${SHEEP_OPTIONS:-"-n -y 127.0.0.1 -l level=debug"}
export DOG_PROG=${DOG_PROG:-../../dog/dog}
export DOG=${DOG:-$DOG_PROG}
export VALGRIND_OPTIONS=${VALGRIND_OPTIONS:-"-q"}
export MD=${MD:-false}
export EC=${EC:-false}
export QEMU_IO=${QEMU_IO_PROG:-qemu-io}
export QEMU_IMG=${QEMU_IMG_PROG:-qemu-img}
export SHEEPFS=${SHEEPFS:-../../sheepfs/sheepfs}
export SOURCE=${SOURCE:-../..}

export TGTD=${TGTD_PROG:-tgtd}
export TGTADM=${TGTADM_PROG:-tgtadm}
export ISCSID=${ISCSID_PROG:-iscsiadm}
export ISCSIADM=${ISCSIADM_PROG:-iscsiadm}
export SCSI_ID=${SCSI_ID_PROG:-/lib/udev/scsi_id}
export MULTIPATHD=${MULTIPATHD_PROG:-multipathd}

# make sure this script returns success
/bin/true
